﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace BullsAndCowsTests
{
    
    
    /// <summary>
    ///This is a test class for BullsAndCowsTest and is intended
    ///to contain all BullsAndCowsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BullsAndCowsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for BullsAndCows Constructor
        ///</summary>
        [TestMethod()]
        public void BullsAndCowsConstructorTest()
        {
            BullsAndCows target = new BullsAndCows();
            uint zero = 0;
            Assert.AreEqual(zero, target.Attemps);
            Assert.AreEqual(zero, target.BullsCount);
            Assert.AreEqual(zero, target.CowsCount);
        }

        /// <summary>
        ///A test for CalculateSecretNumber
        ///</summary>
        [TestMethod()]
        [DeploymentItem("CowsBulls.exe")]
        public void CalculateSecretNumberTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            int number = 7158; // TODO: Initialize to an appropriate value
            target.CalculateSecretNumber(number);
            Assert.IsTrue(target.SecretNumberArray[0] == 7);
            Assert.IsTrue(target.SecretNumberArray[1] == 1);
            Assert.IsTrue(target.SecretNumberArray[2] == 5);
            Assert.IsTrue(target.SecretNumberArray[3] == 8);
        }

        /// <summary>
        ///A test for CowsCount
        ///</summary>
        [TestMethod()]
        public void CowsCountTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            uint expected = 100; // TODO: Initialize to an appropriate value
            uint actual;
            target.CowsCount = expected;
            actual = target.CowsCount;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SecretNumberArray
        ///</summary>
        [TestMethod()]
        public void SecretNumberArrayTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            uint[] expected = new uint[] {1,2,3,4}; // TODO: Initialize to an appropriate value
            uint[] actual;
            target.SecretNumberArray = expected;
            actual = target.SecretNumberArray;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for BullsCount
        ///</summary>
        [TestMethod()]
        public void BullsCountTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            uint expected = 123; // TODO: Initialize to an appropriate value
            uint actual;
            target.BullsCount = expected;
            actual = target.BullsCount;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Attemps
        ///</summary>
        [TestMethod()]
        public void AttempsTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            uint expected = 4; // TODO: Initialize to an appropriate value
            uint actual;
            target.Attemps = expected;
            actual = target.Attemps;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ResetGame
        ///</summary>
        [TestMethod()]
        public void ResetGameTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.ResetGame();
            Assert.IsTrue(target.Attemps == 0);
            Assert.IsTrue(target.BullsCount == 0);
            Assert.IsTrue(target.CowsCount == 0);
        }

        /// <summary>
        ///A test for RepresentGuestNumberInArray
        ///</summary>
        [TestMethod()]
        public void RepresentGuestNumberInArrayTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            int guessNumber = 3623; // TODO: Initialize to an appropriate value
            uint[] expected = new uint[] {3,6,2,3}; // TODO: Initialize to an appropriate value
            uint[] actual;
            actual = target.RepresentGuestNumberInArray(guessNumber);
            Assert.IsTrue(expected[0] == actual[0]);
            Assert.IsTrue(expected[1] == actual[1]);
            Assert.IsTrue(expected[2] == actual[2]);
            Assert.IsTrue(expected[3] == actual[3]);
        }

        /// <summary>
        ///A test for IsGuestNumberRight
        ///</summary>
        [TestMethod()]
        public void IsGuestNumberRightTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.CalculateSecretNumber(1234);
            target.SecretNumber = 1234;
            int guestNumber = 1234; // TODO: Initialize to an appropriate value
            bool actual = target.IsGuestNumberRight(guestNumber);
            Assert.IsTrue(actual);
        }


        /// <summary>
        ///A test for GetCows
        ///</summary>
        [TestMethod()]
        public void GetCowsTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.CalculateSecretNumber(4123);
            uint[] guestNumberArray = new uint[] {1,2,3,4}; // TODO: Initialize to an appropriate value
            target.GetCows(guestNumberArray);
            Assert.IsTrue(target.CowsCount == 4);
        }

        /// <summary>
        ///A test for GetBulls
        ///</summary>
        [TestMethod()]
        public void GetBullsTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.CalculateSecretNumber(1234);
            uint[] guestNumberArray = new uint[] { 1, 2, 3, 4 }; // TODO: Initialize to an appropriate value
            target.GetBulls(guestNumberArray);
            Assert.IsTrue(target.BullsCount == 4);
        }

        /// <summary>
        ///A test for GenerateSecretNumber
        ///</summary>
        [TestMethod()]
        public void GenerateSecretNumberTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.GenerateSecretNumber();
            target.CalculateSecretNumber(target.SecretNumber);
            Assert.IsTrue(target.SecretNumberArray[0] >= 0 && target.SecretNumberArray[0] <= 9);
            Assert.IsTrue(target.SecretNumberArray[1] >= 0 && target.SecretNumberArray[1] <= 9);
            Assert.IsTrue(target.SecretNumberArray[2] >= 0 && target.SecretNumberArray[2] <= 9);
            Assert.IsTrue(target.SecretNumberArray[3] >= 0 && target.SecretNumberArray[3] <= 9);
        }

        /// <summary>
        ///A test for PlayGame
        ///</summary>
        [TestMethod()]
        [Ignore]
        public void PlayGameTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.PlayGame();
        }

        /// <summary>
        ///A test for GetSecretDigit
        ///</summary>
        [TestMethod()]
        public void GetSecretDigitTest()
        {
            BullsAndCows target = new BullsAndCows(); // TODO: Initialize to an appropriate value
            target.CalculateSecretNumber(1234);
            string result = target.GetSecretDigit();
            int count = 0;
            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] == 'X')
                    count++;
            }
            Assert.IsTrue(count == 3);
        }
    }
}
